<?php
define('ROOT_PATH',	realpath(dirname(__FILE__) . '/../../'));

// xml content
$xmlString	= file_get_contents(ROOT_PATH . '/resource/OpenDocument-schema-v1.1.rng');

// prepare namespace for simple xml
$xmlString	= str_replace('xmlns=', 'ns=', $xmlString);
$xml		= simplexml_load_string($xmlString);


$defines = array();
foreach ($xml->xpath('//define') as $d) {
	$defines[ (string)$d['name'] ] = true;
}
$defines = array_keys($defines);
sort($defines);

/*
function span_definition(SimpleXMLElement $el) {
	if (empty($el)) {
		return;
	}
	foreach ($el->children() as $tag => $elements) {
		$tag = (string)$tag;
		if ('ref' == $tag) {
			
		}
		echo '<pre>'; var_dump($tag); echo '</pre>';	
	}
	return;
	foreach ($el->children() as $child) {
		echo "name:";
		echo '<pre>'; var_dump($child); echo '</pre>';
		echo (string)$child;
		echo "<br />";
	}
}
/ */
if (isset($_GET['tag'])) {
	$el		= $xml->xpath("//define[@name='{$_GET['tag']}']");
	span_definition($el[0]);
	
	$tag	= htmlentities($el[0]->asXml());
	$debug	= array();
	/*
	if (!empty($el)) {
		foreach ($el as $t) {
			$debug[] = $t;
		}
	}
	*/
}